//
//  CoinDetialListCell.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/5/31.
//

#import "CoinDetialListCell.h"

@interface CoinDetialListCell()

@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UIImageView *coinImageView;
@property(nonatomic,strong)UILabel *coinLabel;

@end

@implementation CoinDetialListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    self.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    __weak typeof(self)self_weak_ = self;
    self.coinLabel = [[UILabel alloc]init];
    self.coinLabel.font = JPUIFontInterMedium(14);
    self.coinLabel.textColor = KFontBlackColor;
    self.coinLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.coinLabel];
    CGFloat c_w = [self getStringWidthWithText:self.coinLabel.text font:self.coinLabel.font viewHeight:17];
    [self.coinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(@-20);
        make.width.mas_equalTo(c_w+4);
        make.height.mas_equalTo(@17);
        make.top.mas_equalTo(@16);
    }];
    self.coinImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.coinImageView];
    [self.coinImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(@16);
        make.right.mas_equalTo(self_weak_.coinLabel.mas_left);
        make.centerY.mas_equalTo(self_weak_.coinLabel);
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = JPUIFontPingFangSCMedium(16);
    self.titleLabel.textColor = KFontBlackColor;
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@20);
        make.top.mas_equalTo(@0);
        make.height.mas_equalTo(@22);
        make.right.mas_equalTo(self_weak_.coinImageView.mas_left).offset(-10);
    }];
    
    self.timeLabel = [[UILabel alloc]init];
    self.timeLabel.font = JPUIFontPingFangSCRegular(14);
    self.timeLabel.textColor = KFontGrayColor;
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@20);
        make.top.mas_equalTo(self_weak_.titleLabel.mas_bottom).offset(6);
        make.height.mas_equalTo(@20);
        make.right.mas_equalTo(self_weak_.coinImageView.mas_left).offset(-10);
    }];
    
}

-(void)setModel:(ScoreDetialListModel *)model{
    _model = model;
    self.titleLabel.text = model.dictDataName;
    self.timeLabel.text = model.createTime;
    if(model.dictDataCode.integerValue < 0){
        self.coinImageView.image = [UIImage imageNamed:@"mine_coin_changecoin"];
    }else{
        self.coinImageView.image = [UIImage imageNamed:@"mine_coin_changecoin2"];
    }
    self.coinLabel.text = model.dictDataCode;
    CGFloat c_w = [self getStringWidthWithText:self.coinLabel.text font:self.coinLabel.font viewHeight:17];
    [self.coinLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        if(model.dictDataCode.integerValue < 0){
            make.width.mas_equalTo(c_w+6);
        }else{
            make.width.mas_equalTo(c_w+4);
        }
    }];
    __weak typeof(self)self_weak_ = self;
    [self.coinImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self_weak_.coinLabel.mas_left);
    }];
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self_weak_.coinImageView.mas_left).offset(-10);
    }];
    [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self_weak_.coinImageView.mas_left).offset(-10);
    }];
    
}



@end
